package cn.dapeng.retry.t01;

public class TestCase {

    public static final int TIMES = 3;

    public final static int SECONDS = 5;

    public static void main(String[] args) {
        retry(0, 0);
    }

    public static void retry(int times, int delaySeconds) {
        if (times >= TIMES) {
            return;
        }
        try {
            long executeSeconds = System.currentTimeMillis() / 1000 + delaySeconds;

            for (; ; ) {
                while (System.currentTimeMillis() / 1000 >= executeSeconds) {
                    System.out.println("我来了" + System.currentTimeMillis() / 1000);
                    throw new RuntimeException("异常");
                }
            }
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                retry(times + 1, delaySeconds + SECONDS);
            }
            if (times == TIMES - 1) {
                e.printStackTrace();
            }
        }
    }

}
